using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace IS.Base
{

    public class spParam
    {
        public string name;
        public SqlDbType type;
        public Object data;
        public ParameterDirection direction = ParameterDirection.Input;
        public int size = 0;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sName"></param>
        /// <param name="oType"></param>
        /// <param name="oData"></param>
        public spParam(string sName, SqlDbType oType, Object oData)
        {
            //for input init
            name = sName;
            type = oType;
            if ((type == SqlDbType.DateTime && oData.ToString() == ""))
            {
                data = null;
            }
            else
            {
                data = oData;
            }
        }
        public spParam(string sName, string oType, Object oData)
        {
            //for input init
            name = sName;
            type = SQLBase.getType(oType);
            data = oData;
        }
        public spParam(string sName, Object oData)
        {
            name = sName;
            type = SQLBase.GenType(Type.GetTypeCode(oData.GetType()));
            data = oData;
        }
        public spParam(string sName, SqlDbType oType, Object oData, ParameterDirection pDirection)
        {
            //for output init
            name = sName;
            type = oType;
            data = oData;
            direction = pDirection;
        }
        public spParam(string sName, string oType, Object oData, ParameterDirection pDirection)
        {
            //for output init
            name = sName;
            type = SQLBase.getType(oType);
            data = oData;
            direction = pDirection;
        }
        public spParam(string sName, SqlDbType oType, ParameterDirection pDirection)
        {
            //for output init, type is cursor
            name = sName;
            type = oType;
            direction = pDirection;
        }
        public spParam(string sName, string oType, ParameterDirection pDirection)
        {
            //for output init, type is cursor
            name = sName;
            type = SQLBase.getType(oType);
            direction = pDirection;
        }

        public spParam(string sName, SqlDbType oType, ParameterDirection pDirection, int iSize)
        {
            //for output init, type is not cursor
            name = sName;
            type = oType;
            direction = pDirection;
            size = iSize;
        }
        public spParam(string sName, string oType, ParameterDirection pDirection, int iSize)
        {
            //for output init, type is not cursor
            name = sName;
            type = SQLBase.getType(oType);
            direction = pDirection;
            size = iSize;
        }
        //static function to create oracle parameter
        public static SqlParameter createPara(string sName, SqlDbType oType, ParameterDirection pDirection)
        {
            SqlParameter pr = new SqlParameter(sName, oType);
            pr.Direction = pDirection;
            return pr;
        }
        public static SqlParameter createPara(string sName, string oType, ParameterDirection pDirection)
        {
            SqlParameter pr = new SqlParameter(sName, SQLBase.getType(oType));
            pr.Direction = pDirection;
            return pr;
        }
        public static SqlParameter createPara(string sName, SqlDbType oType, ParameterDirection pDirection, int iSize)
        {
            SqlParameter pr = new SqlParameter(sName, oType);
            pr.Direction = pDirection;
            pr.Size = iSize;
            return pr;
        }
        public static SqlParameter createPara(string sName, string oType, ParameterDirection pDirection, int iSize)
        {
            SqlParameter pr = new SqlParameter(sName, SQLBase.getType(oType));
            pr.Direction = pDirection;
            pr.Size = iSize;
            return pr;
        }
        public static SqlParameter createPara(string sName, string oType, Object oData, ParameterDirection pDirection)
        {
            SqlParameter pr = new SqlParameter(sName, SQLBase.getType(oType));
            pr.Value = oData;
            pr.Direction = pDirection;
            return pr;
        }
        public static SqlParameter createPara(string sName, SqlDbType oType, Object oData, ParameterDirection pDirection)
        {
            SqlParameter pr = new SqlParameter(sName, oType);
            pr.Value = oData;
            pr.Direction = pDirection;
            return pr;
        }
        public static SqlParameter createPara(string sName, string oType, Object oData)
        {
            SqlParameter pr = new SqlParameter(sName, SQLBase.getType(oType));
            pr.Value = oData;
            return pr;
        }
        public static SqlParameter createPara(string sName, SqlDbType oType, Object oData)
        {
            SqlParameter pr = new SqlParameter(sName, oType);
            pr.Value = oData;
            return pr;

        }
        public static SqlParameter createPara(string sName, SqlDbType oType, int size, string columnName)
        {
            SqlParameter pr = new SqlParameter(sName, oType, size, columnName);
            return pr;

        }

    }
}